package lvxu.controller;

import com.github.pagehelper.PageInfo;
import lvxu.bean.Msg;
import lvxu.bean.Song;
import lvxu.service.MusicListService;
import lvxu.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
public class SongController {
    @Autowired
    SongService songService;
    @Autowired
    MusicListService musicListService;
    //查询添加歌单所有信息
    @RequestMapping(value = "/songs",method = RequestMethod.GET)
    @ResponseBody
    public Msg getSongInfo(@RequestParam("userid")Integer userid){
        List<Song> songlist = songService.selectByUserIdWithState(userid,1);

        PageInfo<Song> pageInfo = new PageInfo<>(songlist);
        return Msg.success().add("song",pageInfo);
    }
    //删除添加歌单里某一歌曲信息
    @RequestMapping(value = "/songs/{del_id}",method = RequestMethod.DELETE)
    @ResponseBody
    public void deleteSongInfo(@PathVariable("del_id") Integer del_id){
        //1、删除歌单列表里的数据，
        songService.deleteById(del_id,1);
    }
    //查询收藏歌单所有信息
    @RequestMapping(value = "/collect",method = RequestMethod.GET)
    @ResponseBody
    public Msg getCollectInfo(@RequestParam("userid") Integer userid){
        List<Song> collectlist = songService.selectByUserIdWithState(userid,0);
        //导航页码数
        PageInfo<Song> pageInfo = new PageInfo<>(collectlist);
        return Msg.success().add("collect",pageInfo);
    }
    //删除收藏歌单里某一歌曲信息
    @RequestMapping(value = "/collect/{del_id}",method = RequestMethod.DELETE)
    @ResponseBody
    public Msg deleteCollectInfo(@PathVariable("del_id") Integer del_id){
        //1、删除收藏列表里的数据，
        songService.deleteById(del_id,0);
        boolean updateMusicLike = musicListService.updateMusicLike(del_id, "del");
        //2、修改歌曲列表里的该歌曲的收藏状态
        return updateMusicLike?Msg.success():Msg.fail();
    }
}
